package de.slash.jplaylistextractor.common;

import de.slash.jplaylistextractor.utils.Utility;
import org.jdesktop.swingx.JXErrorPane;
import org.jdesktop.swingx.error.ErrorInfo;

import javax.swing.*;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * User: Slash
 * Date: 17.03.2012
 * Time: 12:05
 */
public class ExceptionHandler
{
    private Logger logger;
    private Utility util;
    private ResourceBundle resourceBundle;
    private JFrame frame;

    public ExceptionHandler(Logger pLogger, ResourceBundle pResourceBundle, JFrame pFrame)
    {
        logger = pLogger;
        logger.setLevel(Level.SEVERE);
        util = new Utility();
        resourceBundle = pResourceBundle;
        frame = pFrame;
    }

    public void handleException(Exception pException)
    {
        logger.severe(util.convertStackTraceToString(pException));
        ErrorInfo info = new ErrorInfo(resourceBundle.getString("Error"), resourceBundle.getString("Error_Message"), null, "category", pException, Level.ALL, null);
        JXErrorPane.showDialog(frame, info);
    }
}
